<template>
  <div
    class="card-list"
    :class="isSwiper ? 'is-swiper-scitve' : ''"
    :style="{ 'white-space': isWrap ? 'normal' : 'nowrap' }"
  >
    <div class="card-box" v-for="item in cardList" :key="item.id">
      <div class="card">
        <img :src="item.imgHost+item.imgUrl" alt="" />
        <a
          href="javascript:;"
          class="card-tag"
          @click="handleDetails(item.path)"
          >{{ item.tag }}</a
        >
        <a
          href="javascript:;"
          @click="handleDetails(item.path,'/content-article/'+item.id)"
          >{{ item.title }}</a
        >
        <div class="card-foot">
          <div>{{ item.createTime }}</div>
          <div>
            <span class="iconfont icon-dianzan1">{{ item.like_num }}</span>
            <span class="iconfont icon-Icon-guankanliang">{{
              item.look_num
            }}</span>
            <span class="iconfont icon-xiaoxi">0</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations,mapActions } from "vuex";
export default {
  props: {
    num: Number,
    distance: Number,
    isWrap: Boolean,
    isSwiper: Boolean,
    cardList: Array,
  },
  data() {
    return {};
  },
  watch: {
    num() {
      document.querySelector(
        ".is-swiper-scitve"
      ).style.transform = `translate(-${this.num * this.distance}px)`;
    },
    distance() {
      document.querySelector(
        ".is-swiper-scitve"
      ).style.transform = `translate(-${this.num * this.distance}px)`;
    },
  },
  methods: {
    ...mapActions(['handleSetActiveArr']),
    async handleDetails(path, pathId) {
      await this.handleSetActiveArr({path,app:this})
      if (pathId) {
        this.$router.push({
          path:pathId
        });
      } else {
        this.$router.push({
          path
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
@media only screen and (min-width: 1240px) {
  .card-box {
    width: 25%;
  }
}
@media only screen and (min-width: 992px) and (max-width: 1240px) {
  .card-box {
    width: 25%;
    .card-foot {
      div {
        white-space: initial;
        span {
          &:nth-last-child(1) {
            display: none;
          }
        }
      }
    }
  }
}
@media only screen and (max-width: 992px) {
  .card-list {
    // white-space: normal !important;
    .card-box {
      width: 50%;
    }
  }
  .card-list.is-swiper-scitve {
    // white-space: nowrap !important;
  }
}

@media only screen and (max-width: 768px) {
  .card-list {
    // white-space: normal !important;
    .card-box {
      .card-foot {
        div {
          white-space: initial;
          span {
            &:nth-last-child(1),
            &:nth-last-child(2) {
              display: none;
            }
          }
        }
      }
    }
  }
  .card-list.is-swiper-scitve {
    // white-space: nowrap !important;
  }
}
.card-list {
  box-sizing: border-box;
  // white-space: nowrap;
  transition: transform 1s;
  .card-box {
    display: inline-block;
    padding: 10px;
    box-sizing: border-box;
    .card {
      box-sizing: border-box;
      width: 100%;
      flex: 1;
      border: 1px solid #eeeeee;
      overflow: hidden;
      border-radius: 5px;
      position: relative;
      transition: all 0.3s;
      top: 0;
      img {
        width: 100%;
        cursor: pointer;
      }
      .card-tag {
        width: initial;
        height: initial;
        position: absolute;
        top: 15px;
        left: 15px;
        padding: 5px 10px;
        margin: 0;
        font-size: 12px;
        border-radius: 5px;
        color: #fff;
        background: rgba(0, 0, 0, 0.6);
        &:hover {
          color: #fff;
          background: #3361ea;
        }
      }
      a {
        width: calc(100% - 28px);
        height: 42px;
        white-space: normal;
        margin: 14px;
        box-sizing: border-box;
        color: #000;
        &:hover {
          color: #3361ea;
        }
        line-height: 1.4;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
      }
      .card-foot {
        display: flex;
        justify-content: space-between;
        margin: 0 15px 15px;
        div {
          color: #aaa;
          font-size: 12px;
          .iconfont {
            font-size: 12px;
            margin-left: 5px;
            &::before {
              margin-right: 2px;
            }
          }
          .icon-xiaoxi {
            cursor: pointer;
          }
        }
      }
      &:hover {
        top: -5px;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.2);
      }
    }
  }
}
</style>